// 这份代码专门处理逻辑层的操作
const fileDao = require('../dao/fileDao');
const powerDao = require('../dao/powerDao');

const fileService = {
    async downloadPublicFile(fileId, uid) {
        let result;
        // 鉴权
        try {
            let power = await powerDao.checkPower(uid, '下载文件');
            if (power.length == 0) {
                result = { success: false, msg: '权限不足' };
                return result;
            }
        } catch (err) {
            result = { success: false, msg: "数据库异常" };
            return result;
        }
        // 业务逻辑
        try {
            result = await fileDao.downloadPublicFile(fileId);
            result = { success: result.success, data: result };
        } catch (err) {
            result = { success: false, msg: "数据库异常" };
        }
        return result;
    }
};

module.exports = fileService;